
#-----------------------------------------------------------------------------
# Makefile
#-----------------------------------------------------------------------------

TARGET  = triangulate

#-----------------------------------------------------------------------------
# On Linux,    this should be 'Linux'
# On Mac OS X, this should be 'MAC_OS_X'
#-----------------------------------------------------------------------------

PLATFORM := $(shell uname -s)
MACHINE := $(shell uname -m)

ifeq ($(PLATFORM),Linux)
  ifeq ($(MACHINE),x86_64)
    PLATFORM := LINUX64
  else
    PLATFORM := LINUX
  endif
else
  ifeq ($(PLATFORM),Darwin)
    PLATFORM := MAC_OS_X
  else
    PLATFORM := OTHER
  endif
endif


#-----------------------------------------------------------------------------
# Choose a compiler & its options
#--------------------------------------------------------------------------

CXX      = g++
LINK     = g++

OPTS = -ansi -MMD -W -g -Wno-deprecated  
ifeq ($(PLATFORM),MAC_OS_X)
 OPTS += -DMACOS
endif

#--------------------------------------------------------------------
# Xlib and OpenGL
#--------------------------------------------------------------------

ifeq ($(PLATFORM),MAC_OS_X)
   GL_LIB = -framework OpenGL -framework GLUT -framework Foundation
else
   X_LIB  = -Wl,-rpath,/usr/X11R6/lib -L/usr/X11R6/lib -L/usr/local/lib -lXext -lX11 -lXt 
   GL_LIB = -lglut -lGLU -lGL -lm
endif

#--------------------------------------------------------------------
# MPFR
#--------------------------------------------------------------------

ifeq ($(PLATFORM),MAC_OS_X)
	MPFR_DIR = /opt/local
	MPFR_INCL= -I${MPFR_DIR}/include
	MPFR_LIB = -L${MPFR_DIR}/lib -lmpfr -lgmp
else
	MPFR_LIB = -lmpfr -lgmp
endif
		
#--------------------------------------------------------------------
# Put all together
#--------------------------------------------------------------------
SUBDIRS = . 
INCLUDE = $(addprefix -I,$(SUBDIRS)) $(TRI_INCL) $(MPFR_INCL)
SRCS=$(wildcard $(addsuffix /*.cpp,$(SUBDIRS)))
OBJS=${SRCS:.cpp=.o}
LIB = $(X_LIB) $(GL_LIB) $(MPFR_LIB)

CFLAGS   = $(OPTS) $(INCLUDE) 
CXXFLAGS = $(CFLAGS) 


.PHONY: all
all :  $(TARGET)

#--------------------------------------------------------------------

#--------------------------------------------------------------------
$(TARGET): $(OBJS)
	${CXX} ${CXXFLAGS} -o $@ $(OBJS) $(LIB)

clean:
	-rm -f $(OBJS) $(TARGET) Dependencies

#--------------------------------------------------------------------
.SUFFIXES: .cpp

.cpp.o:
	${CXX} ${CXXFLAGS} -c $< -o $@
	cat $*.d >> Dependencies
	rm -f $*.d 

Dependencies:
	touch Dependencies

include Dependencies


